package test;

import java.util.Map;

class SQLFormatter {
    static  String url(int port){
        return url("127.0.0.1",port);
    }
    static String url(String path,int port){
        return "jdbc:MySQL://"+path+":"+port;
    }
    static String url(int port, String schema,Map<String,String> constraints){
        StringBuffer stringBuffer=new StringBuffer(url(port));
        stringBuffer.append('/').append(schema);
        boolean first=true;
        for(String constraint:constraints.keySet()){
            if(first){
                stringBuffer.append('?');
                first=false;
            }
            else stringBuffer.append('&');
            stringBuffer.append(constraint+"="+constraints.get(constraint));
        }
        return stringBuffer.toString();
    }
}
